package br.com.foxinline.servico;

import br.com.foxinline.modelo.Imovel;
import br.com.foxinline.modelo.Pessoa;
import br.com.foxinline.modelo.Transferencia;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author cadomeireles
 */
@Stateless
public class TransferenciaServico extends ServicoGenerico<Transferencia> {

    public TransferenciaServico() {
        super(Transferencia.class);
    }

    public Transferencia obterTransferenciaAtual(Imovel imovel) {
        String sql = "select transferencia from Transferencia transferencia where transferencia.atual = true and transferencia.imovel = :imovel";
        
        Query query = getEntityManager().createQuery(sql);
        
        if (imovel != null && imovel.getId() != null) {
            query.setParameter("imovel", imovel);
        }

        return (Transferencia) query.getSingleResult();
    }

    public List<Pessoa> pesquisarAdquirentes(Transferencia transferencia) {
        String sql = "select transferencia.adquirente from Transferencia transferencia where transferencia = :transferencia";
        
        Query query = getEntityManager().createQuery(sql);
        
        if (transferencia != null && transferencia.getId() != null) {
            query.setParameter("transferencia", transferencia);
        }

        return query.getResultList();
    }

    public List<Pessoa> pesquisarTransmitentes(Transferencia transferencia) {
        String sql = "select transferencia.transmitente from Transferencia transferencia where transferencia = :transferencia";
        
        Query query = getEntityManager().createQuery(sql);
        
        if (transferencia != null && transferencia.getId() != null) {
            query.setParameter("transferencia", transferencia);
        }

        return query.getResultList();
    }

}
